def searchMatrix(matrix, target):
    i, j = len(matrix) - 1, 0
    while i >= 0 and j < len(matrix[0]):
        if matrix[i][j] > target:
            i -= 1
        elif matrix[i][j] < target:
            j += 1
        else:
            return True
    return False
s = input().split(" ")
n = int(s[0])
m = int(s[1])
target = int(s[2])
matrix = [None] * n
for i in range(n):
    matrix[i] = [int(x) for x in input().split(" ")]
print(searchMatrix(matrix, target))